/**
 * Copyright 2008 Matthew Purland (m.purland@gmail.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.variance.version.identifier;

/**
 * Identify a revision stage of a revision capable object by an integer.
 *
 * The revision identifier starts with 1.
 *
 * @author Matthew Purland
 */
public class IntegerRevisionIdentifier extends AbstractRevisionIdentifier<Integer> {

    // Internal revision identifer
    private int revisionIdentifier;

    public IntegerRevisionIdentifier(
            RevisionIdentifierSource revisionIdentifierSource,
            int revisionIdentifier) {
        super(revisionIdentifierSource);
        this.revisionIdentifier = revisionIdentifier;
    }

    /**
     * {@inheritDoc}
     */
    public int compareTo(RevisionIdentifier o) {
        if (o instanceof IntegerRevisionIdentifier) {
            IntegerRevisionIdentifier integerRevisionIdentifier = (IntegerRevisionIdentifier) o;

            // If the revision identifier is greater
            if (getIdentifier() > integerRevisionIdentifier
                    .getIdentifier()) {
                return 1;
            }
            // If the revision identifier is less than
            else if (getIdentifier() < integerRevisionIdentifier
                    .getIdentifier()) {
                return -1;
            }
            // If the revision identifier is equal
            else {
                return 0;
            }
        } else {
            throw new ClassCastException("Object cannot be compared with "
                    + this.getClass().getName());
        }
    }

    /**
     * {@inheritDoc}
     */
    public Integer getIdentifier() {
        return revisionIdentifier;
    }    
}
